//
//  AFNModel.m
//  LifeShopping
//
//  Created by panxue on 16/1/16.
//  Copyright © 2016年 panxue. All rights reserved.
//

#import "AFNModel.h"
#import <AFNetworking.h>

@implementation AFNModel

+ (void)GETWithURL:(NSString *)str completion:(NETBLOCK)netblock
{
    //中文转码
    NSString *newStr = [str stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet characterSetWithCharactersInString:str]];

//    newStr = [newStr stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
    
    //创建AFN管理
    AFHTTPSessionManager *seccionManager = [AFHTTPSessionManager manager];
    seccionManager.responseSerializer = [AFHTTPResponseSerializer serializer];
    
    //进行get请求
    [seccionManager GET:newStr parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
        NSLog(@"%lld", downloadProgress.totalUnitCount);
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        //JSON解析
        id result = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableContainers error:nil];
        netblock(result);
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        NSLog(@"%@", error);
        
    }];
}

@end
